package com.ibm.workplace.wcm.cqplugin;

public class BugPriority {

    public static final BugPriority NONE = new BugPriority("none", "", 0);
    public static final BugPriority LOW = new BugPriority("low", "Low", 1);
    public static final BugPriority MEDIUM = new BugPriority("medium", "Medium", 2);
    public static final BugPriority HIGH = new BugPriority("high", "High", 3);

    private String code;
    private String description;
    private int value;

    private static BugPriority[] BUG_PRIORITIES;

    static {
        BUG_PRIORITIES = new BugPriority[] { NONE, LOW, MEDIUM, HIGH };
    }

    private BugPriority(String code, String description, int value) {
        super();

        this.code = code;
        this.description = description;
        this.value = value;
    }

    public String getDescription() {
        return description;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean equals(Object o) {
        if (o != null && o instanceof BugPriority) {
            return o == this || code.equalsIgnoreCase(((BugPriority) o).getCode());
        } else {
            return false;
        }
    }

    public static BugPriority getBugPriorityFromCode(String code) {
        if (code != null) {
            for (int i = 0; i < BUG_PRIORITIES.length; i++) {
                if (BUG_PRIORITIES[i].getCode().equals(code)) {
                    return BUG_PRIORITIES[i];
                }
            }
        }

        return NONE;
    }
    
    public String toString() {
        return value + "_" + code;
    }
}
